package com.mengdee.manage.controller;

import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * Created by mengday.zhang on 2017/12/19.
 */
@Controller
@RequestMapping("/api/v1")
@Api(description = "API接口")
public class ApiController {

    @ApiOperation(value = "用户登录", notes = "用户登录接口")
    @ApiResponses({
            @ApiResponse(code = 0, message = "success"),
            @ApiResponse(code = 10001, message = "用户名错误", response = IllegalArgumentException.class),
            @ApiResponse(code = 10002, message = "密码错误")
    })
    @RequestMapping(value = "/user/login", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8;"})
    @ResponseBody
    public String login(@ApiParam(name = "username", value = "用户名", required = true) @RequestParam String username,
                        @ApiParam(name = "password", value = "密码", required = true) @RequestParam String password){
        return "{'username':'" + username + "', 'password':'" + password + "'}";
    }


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "phone", dataType = "String", required = true, value = "手机号"),
            @ApiImplicitParam(paramType = "query", name = "nickname", dataType = "String", required = true, value = "nickname", defaultValue = "双击666"),
            @ApiImplicitParam(paramType = "path", name = "platform", dataType = "String", required = true, value = "平台", defaultValue = "PC"),
            @ApiImplicitParam(paramType = "body", name = "password", dataType = "String", required = true, value = "密码")
    })
    @RequestMapping(value = "/{platform}/user/regist", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8;"})
    @ResponseBody
    public String regist(@RequestHeader String phone, @RequestParam String nickname, @PathVariable String platform, @RequestBody String password){
        return "{'username':'" + phone + "', 'nickname':'" + nickname + "', 'platform': '" + platform + "', 'password':'"+password+"'}";
    }

    @RequestMapping(value = "/user/list", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8;"})
    @ResponseBody
    public String getUserList(Pager pager){
        return "[{'id': "+pager.getPage()+", 'username': 'zhangsan"+pager.getSize()+"'}]";
    }

    @RequestMapping("/docs")
    @ApiIgnore
    public String test(){
        return "api-docs";
    }
}
